
#include "outf.h"
/* #include <stdarg.h> */
/* #include "printf.h" */
#include "dev.h"
#include "USART.h"
#include "VCom.h"
#include "debug.h"
#include "string.h"

char* s, buffer[256];

int outf ( int Device, const char *format, ... )
{

	s = buffer;

	va_list args;
	va_start( args, format );
	
	int res = 0;

	res = print(&s, format, args);

	switch( Device )
	{
		case DEV_ALL_DBG:
			putstr(buffer, DEV_PORT_A);
			if ( g_debug )
			{
				VCOM_puts(buffer);
			}
			break;

		case DEV_ALL:
			putstr(buffer, DEV_PORT_A);
			VCOM_puts(buffer);
			break;
		
		case DEV_PORT_A:
			putstr(buffer, DEV_PORT_A);
			break;

		case DEV_MODEM:
			StrCat(buffer, "\r");
			putstr(buffer, DEV_MODEM);
			break;

		case DEV_VCOM:
			VCOM_puts(buffer);
			Vcom_Transmit();
			break;

	
		case DEV_SMS:
			/* print( &s, format, args ); */
/* 			buffer[124] = 0; */
/* 			SMS_Add_Message(SMS_SystemMesage_Header.SenderPhone, buffer); */
			putstr(buffer, DEV_PORT_A);
			break;
			


		default:
			;
	}

//	DBG("\n%s; Device: %d\n",__FUNCTION__,Device); 

	va_end(args);

	return res;
}
